<template>
  <div class="box">
    <!-- 下拉搜索 -->
    <div class="iconSelect" @click="round">
      <div :class="{ iconActive1: this.active, iconActive: !this.active }"></div>
    </div>
    <!-- 下拉搜索框 -->
    <!-- 头部 -->

    <div class="header">
      <a href="#" class="logo"></a>
      <router-link to="/search">
        <div class="search">
          <van-icon name="search" class="icon" />
          <span class="text">搜索商品, 共121077款好物</span>
        </div>
      </router-link>
      <router-link class="loginBtn" to="/login">登录</router-link>
    </div>

    <!-- 下拉搜索 -->
    <!-- 滚动列表 -->
    <van-tabs line-height="1px" @click="handler">
      <van-tab title="推荐 ">
        <!-- Middle -->
        <Middle></Middle>
      </van-tab>
      <van-tab v-for="(nav, index) in cateList" :title="nav.name" :key="index">
        <Bottom :categoryId="nav.id"></Bottom>
      </van-tab>
    </van-tabs>
  </div>
</template>
<script>
import Vue from "vue";
import { Icon, Tab, Tabs, Swipe, SwipeItem } from "vant";

Vue.use(Icon);
Vue.use(Swipe);
Vue.use(SwipeItem);
Vue.use(Icon);
Vue.use(Tab);
Vue.use(Tabs);


import Bottom from "./bottom/index.vue";
import { mapGetters, mapState } from "vuex";
import Middle from "./components/middle.vue";

export default {
  // 组件名字
  name: "Home",
  // 状态数据
  data() {
    return {
      value: "",
      active: false,
    };
  },
  components: {
    Bottom,
    Middle
  },
  mounted() {
    // 获取首页数
    this.getHomeData();
    this.getNavList();
  },
  methods: {
    showPopup() {
      this.show = true;
    },
    //标签点击事件 每次点击都发请求里的数据
    handler(name, title) {
      let index = name - 1;
      // console.log(index);
      if (index < 0) index = 1;
      // console.log(index);
      // console.log(this.cateList[index].id);

      this.getGoodsList(this.cateList[index].id);
    },
    // home页面头部搜索三角的回调
    round() {
      this.active = !this.active;
    },
    // 获取home页数据
    getHomeData() {
      this.$store.dispatch("home/getHomeData");
    },
    getNavList() {
      this.$store.dispatch("home/getNavList");
    },
    // 获取导航分类下的商品数据列表
    getGoodsList(id) {
      // console.log(123);
      this.$store.dispatch("home/getGoodsList", id);
    },
  },

  computed: {
    ...mapGetters("home", ["categoryList", "cateList"]),
  },
};
</script>
<style lang="less" scoped>
.box {
  width: 100%;
  height: 100%;

  .iconSelect {
    width: 50px;
    height: 25px;
    position: absolute;
    top: 39px;
    right: 0px;
    z-index: 99;
    background-color: white;
    display: flex;
    justify-content: center;
    align-items: center;

    div {
      width: 15px;
      height: 15px;
      background-size: 50px 40px;
      background-image: url("../../assets/icon2.png");
    }

    .iconActive {
      transition: all 0.3s linear;
      transform: rotateZ(0deg);
    }

    .iconActive1 {
      transition: all 0.3s linear;
      transform: rotateZ(180deg);
    }
  }

  .header {
    width: 100%;
    height: 44px;
    // background: pink;
    display: flex;
    align-items: center;
    box-sizing: border-box;
    padding: 8px 15px;

    .logo {
      width: 70px;
      height: 40px;
      display: inline-block;
      margin-right: 10px;
      // background-color: aqua;
      background-image: url(../../assets/02.png);
      // background-size: 100px 100px;
      // background-position: -25px 15px;
      background-size: 195px 195px;
      background-position: -65px 30px;
    }

    .search {
      height: 28px;
      display: flex;
      align-items: center;
      background-color: #ededed;
      flex: 1;
      border-radius: 5px;
      text-align: center;

      .icon {
        width: 14px;
        height: 14px;
        margin: 0px 10px 0px 15px;
        line-height: 14px;
        font-size: 20px;
      }

      .text {
        font-size: 14px;
        margin-right: 5px;
        line-height: 14px;
        text-align: center;
        color: #666;
      }
    }

    .loginBtn {
      width: 35px;
      height: 20px;
      font-size: 14px;
      border: 1px solid #dd1a21;
      border-radius: 5px;
      color: #dd1a21;
      text-align: center;
      margin-left: 8px;
      line-height: 20px;
    }
  }

  :deep(.van-tabs__wrap) {
    height: 20px;
    font-size: 12px;
  }

  :deep(.van-tab--active) {
    color: #dd1a21;
  }

  // .all {
  //   width: 100%;
  //   height: 40px;
  //   background: #fff;
  //   .search {
  //     width: 80px;
  //     margin: 10px;
  //     .allSearch {
  //     }
  //   }
  // }
}
</style>
